<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>nav</title>
</head>
<body>
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-white shadow-sm" style="transition: top .5s">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">
            <img th:src="@{/favicon.ico}" src="../../static/img/logo.png" alt="logo" class="d-inline-block align-text-top" height="36" />
            <span th:text="${profile.name}">Bincker的实验室</span>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarDropdown">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarDropdown">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" th:classappend="${#request.requestURI} == '/' ? 'active' : ''" th:href="@{/}">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/about}">关于</a>
                </li>
            </ul>
        </div>
    </div>
    <script type="module">
        import debounce from "/js/higher/debounce.js"
        (()=>{
            const nav = document.querySelector(".navbar");
            let isPutAway = false;
            let prevScrollTop = 0;
            document.addEventListener("scroll", debounce(()=>{
                const isScrollDown = document.scrollingElement.scrollTop - prevScrollTop > 0;
                if(isScrollDown){
                    if(!isPutAway && document.scrollingElement.scrollTop > 300){//没有收起并且下滑距离大于300
                        nav.style.top = "-" + nav.clientHeight + "px";
                        isPutAway = true;
                    }
                }else{
                    if(isPutAway){//否则为上滑，且已经收起
                        nav.style.top = "0";
                        isPutAway = false;
                    }
                }
                prevScrollTop = document.scrollingElement.scrollTop;
            }, 1000))
        })();
    </script>
</nav>
</body>
</html>
